package com.htthorizon.model.controller;

import java.util.List;

import com.htthorizon.model.request.SysUserModelReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.htthorizon.common.log.annotation.Log;
import com.htthorizon.common.log.enums.BusinessType;
import com.htthorizon.common.security.annotation.RequiresPermissions;
import com.htthorizon.model.domain.SysUserModel;
import com.htthorizon.model.service.ISysUserModelService;
import com.htthorizon.common.core.web.controller.BaseController;
import com.htthorizon.common.core.web.domain.AjaxResult;
import com.htthorizon.common.core.web.page.TableDataInfo;

import javax.validation.Valid;

/**
 * 用户对应模型的操作权限Controller
 *
 * @author mark
 * @date 2023-11-16
 */
@RestController
@RequestMapping("/model/operate")
public class SysUserModelController extends BaseController
{
    @Autowired
    private ISysUserModelService sysUserModelService;

    /**
     * 查询用户对应模型的操作权限列表
     */
    @RequiresPermissions("model:operator:list")
    @GetMapping("/list")
    @Log(title = "模型管理/模型权限配置", businessType = BusinessType.QUERY)
    public TableDataInfo list(SysUserModelReq sysUserModel)
    {
        startPage();
        List<SysUserModelReq> list = sysUserModelService.selectSysUserModelList(sysUserModel);
        return getDataTable(list);
    }


    /**
     * 获取用户对应模型的操作权限详细信息
     */
    @RequiresPermissions("model:operate:query")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        return success(sysUserModelService.selectSysUserModelByModelId(modelId));
    }

    /**
     * 新增用户对应模型的操作权限
     */
    @RequiresPermissions("model:operate:add")
    @Log(title = "模型管理/用户对应模型的操作权限", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Valid @RequestBody SysUserModel sysUserModel){
        return toAjax(sysUserModelService.insertSysUserModel(sysUserModel));
    }


    /**
     * 删除用户对应模型的操作权限
     */
    @RequiresPermissions("model:operate:remove")
    @Log(title = "模型管理/用户对应模型的操作权限", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public AjaxResult remove(@Valid @RequestBody SysUserModel sysUserModel)
    {
        return toAjax(sysUserModelService.deleteSysUserModelByUserId(sysUserModel.getUserId(), sysUserModel.getModelId()));
    }
}
